<template>
  <view class="container">
    <view class="detail-page">


      <view>推荐产品</view>

      <!-- 商品信息 -->
      <view class="product-info" v-for="item in goodsDetail" :key="item.id">
        <!-- 商品主图 -->
        <view class="product-banner">
          <image :src="BASE_URL + item.detailImg" mode="aspectFit" />
        </view>

        <view class="product-header">
          <view class="title">{{ item.name }}</view>
        </view>

        <view class="info-item">
          <text class="label">产品名称</text>
          <text class="value">{{ item.name }}</text>
        </view>

        <view class="info-item">
          <text class="label">使用方法</text>
          <text class="value">{{ item.usageMethod }}</text>
        </view>

      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import { getGoodsDetailCard } from "@/api/goods";
import { BASE_URL, IMG_URL } from "@/utils/request";
import { useUserStore } from "@/stores/user";

const userStore = useUserStore();

interface GoodsInfo {
  id: number;
  name: string;
  price: number;
  typeId: number;
  typeName: string;
  description: string;
  headerImg: string;
}

// 商品详情
const goodsDetail = ref<GoodsInfo[]>();

// 获取商品详情
const fetchGoodsDetailCard = async (id: string) => {
  try {
    const res = await getGoodsDetailCard(Number(id));
    goodsDetail.value = res.data;
    if (res.data?.omsGoodsInfos!.length > 0) {
      goodsDetail.value = res.data.omsGoodsInfos
    } else {
      uni.showToast({
        title: "用户未在测服仪上检测皮肤状况",
        icon: "none",
        duration: 1500,
        success: () => {
          setTimeout(() => {
            uni.navigateBack();
          }, 1500);
        }
      });
    }
  } catch (error) {
    console.error("获取商品详情失败:", error);
    uni.showToast({
      title: "获取商品详情失败",
      icon: "none",
    });
  }
};

// 页面加载
onMounted((options: any) => {
  console.log(999, userStore.userInfo)
  fetchGoodsDetailCard(userStore.userInfo.user.phonenumber);

});

</script>

<style lang="scss" scoped>
.container {
  background: #F3F3FD;
  margin-top:-20rpx;
}


.detail-page {
  background: #fff;
  padding-bottom: 120rpx;
  padding: 10rpx 20rpx;
  width: 706rpx;
  box-sizing: border-box;
  margin: 20rpx auto 0;
  border-radius: 20rpx;
}

.product-banner {
  width: 100%;
  height: 300rpx;
  background: #f8f8f8;

  image {
    width: 100%;
    height: 100%;
  }
}

.product-info {
  padding: 30rpx;

  .product-header {
    margin-bottom: 20rpx;
    margin-top: 20rpx;

    .title {
      font-size: 32rpx;
      color: #333;
      font-weight: bold;
      margin-bottom: 10rpx;
    }
  }

  .price-section {
    display: flex;
    align-items: baseline;
    margin-bottom: 30rpx;

    .price {
      color: #ff4b33;
      margin-right: 20rpx;

      .symbol {
        font-size: 24rpx;
      }

      .amount {
        font-size: 36rpx;
        font-weight: bold;
      }
    }
  }

  .info-item {
    display: flex;
    margin-bottom: 20rpx;

    .label {
      font-size: 28rpx;
      color: #666;
      margin-right: 20rpx;
      min-width: 140rpx;
    }

    .value {
      font-size: 28rpx;
      color: #333;
      flex: 1;
    }
  }

  .section-title {
    font-size: 32rpx;
    color: #333;
    font-weight: bold;
    margin: 40rpx 0 20rpx;
  }

  .description,
  .solution {
    font-size: 28rpx;
    color: #666;
    line-height: 1.6;
  }
}
</style>
